﻿using System;

namespace BSharp.Compiler
{
	public class IfStatement : AstNode
	{
		public readonly AstNode Condition;
		public readonly AstNode Body;
		public readonly AstNode ElseBody;

		public IfStatement (SourceLocation location, AstNode condition, AstNode body, AstNode elseBody = null)
			: base (location)
		{
			Condition = condition;
			Body = body;
			ElseBody = elseBody;
		}

		public override void Visit (AstVisitor visitor)
		{
			visitor.Accept (this);
		}

		public override void VisitChildren (AstVisitor visitor)
		{
			Condition.Visit (visitor);
			Body.Visit (visitor);

			if (ElseBody != null) {
				ElseBody.Visit (visitor);
			}
		}
	}
}

